google.load("visualization", "1", {'packages':["corechart"]});
google.load('visualization', '1', {'packages': ['piechart']});


function drawMtMsChart(mtmresp0) 
{
    var mtmresp = eval('(' + mtmresp0.responseText + ')'); 
	var mtmsdata = new google.visualization.DataTable();
	mtmsdata.addColumn('string', 'time');
	var nDates2 = mtmresp.datesList.length
	var nPlayers = mtmresp.datesList[0].playersList.length

    for( var player = 0; player < nPlayers; player++ )
    {
        mtmsdata.addColumn('number', mtmresp.datesList[0].playersList[player].name);
    }

	mtmsdata.addRows(nDates2);
    for( var date = 0; date < nDates2; date++ )
    {
        mtmsdata.setValue(date, 0, mtmresp.datesList[date].time);
        for( var player = 0; player < nPlayers; player++ )
        {
            mtmsdata.setValue(date, player+1, mtmresp.datesList[date].playersList[player].mtm);
        }
    }

    var mtmschart = new google.visualization.LineChart(document.getElementById('mtmschart_div'));
	mtmschart.draw(mtmsdata, {width: 600, height: 300, title: 'MtMs History', lineWidth:1, pointSize:0, curveType:'function' });
};


var updateMtMsChart = function() 
{
    var args = { type:"get", url:"/json/getMtMsHistory/", complete:drawMtMsChart };
    $.ajax(args);
    return false;
};

$(document).ready( function() 
{
    updateMtMsChart();
});

setInterval( "updateMtMsChart()", 100000 );